/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author gravena
 */
public class ControlParser {
    private byte[] buffer;
    
    public ControlParser(byte[] buffer) {
        this.buffer = buffer;
    }
    
    public long getVersion() {
        byte[] nLong = new byte[8];
        System.arraycopy(this.buffer, 32, nLong, 0, 8);
        
        ByteArrayInputStream bis = new ByteArrayInputStream(nLong);
        DataInputStream dis = new DataInputStream(bis);
        try {
            long version = dis.readLong();
            return version;
        } catch (IOException ex) {
            System.err.println("Erro na leitura do long!\n" + ex.getMessage());
            return -1;
        }
                
    }
    
    public String getUUID() {
        byte[] string = new byte[32];
        ByteArrayInputStream bis = new ByteArrayInputStream(this.buffer);
        DataInputStream dis = new DataInputStream(bis);
        try {
            for(int i=0;i<32;i++) {
                string[i] = dis.readByte();
            }
        } catch (IOException ex) {
            System.err.println("Erro na leitura da string!\n" + ex.getMessage());            
        }                
        //ca4994d7-cfcb-4182-a290-ddee99c9deef
        String temp =  new String(string);
        
        temp = temp.substring(0,8) + "-" + temp.substring(8, 12) + "-" + temp.substring(12,16) + "-" + temp.substring(16, 20) + "-" + temp.substring(20);
        return temp;
    }
}
